package com.surprise.db.dao.join;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.surprise.db.dao.SimpleDAO;
import com.surprise.db.entity.join.SelectPMTalkMst001Entity;

/**
 * SelectPMTalkMst001.java
 * @author xuling
 * @since 2017年2月20日
 */
@Repository
public class SelectPMTalkMst001 extends SimpleDAO<SelectPMTalkMst001Entity> {

	/**
	 * 获得聊天室信息
	 * @param userid 用户ID
	 * @return 聊天室信息
	 */
	public List<SelectPMTalkMst001Entity> select(Long userid) {
		String sql = " SELECT pm_talk_mst.id, pm_talk_mst.fromuser as fromuserid, "
				+ " pm_talk_mst.touser as touserid, pm_talk_mst.content, "
				+ " userA.portrait as fromPortrait, userB.portrait as toPortrait, "
				+ " userA.username as fromUsername, userB.username as toUsername "
				+ " FROM pm_talk_mst "
				+ " INNER JOIN user userA on userA.id = pm_talk_mst.fromuser "
				+ " INNER JOIN user userB on userB.id = pm_talk_mst.touser "
				+ " where pm_talk_mst.fromuser = ? or pm_talk_mst.touser = ? "
				+ " and pm_talk_mst.deleteflg = 0 ORDER BY pm_talk_mst.updatetime DESC ";

		return super.findBySql(sql, userid, userid);
	}
}
